<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.List" %>
<%@ page import="javax.jdo.PersistenceManager" %>
<%@ page import="info.bu2012ie03.Greeting" %>
<%@ page import="info.bu2012ie03.PMF" %>

<html lang="ja">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <link type="text/css" rel="stylesheet" href="BullentinBoard.css">
    <script type = "text/javascript" language="javascript"">
    <!--
    function chkInput() {
        if ((document.input.name.value == "")||
                (document.input.title.value == "")||
                (document.input.content.value == "")){
            window.alert("投稿者、タイトル、内容は必須項目です");
            return false;
        } else {
            return true;
        }
    }
    // -->
    </script>
  </head>

  <body>

    <!-- OPTIONAL: include this if you want history support -->
    <iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position:absolute;width:0;height:0;border:0"></iframe>
    
    <!-- RECOMMENDED if your web app will not function without JavaScript enabled -->
    <noscript>
      <div style="width: 22em; position: absolute; left: 50%; margin-left: -11em; color: red; background-color: blue; border: 1px solid red; padding: 4px; font-family: sans-serif">
        Your web browser must have JavaScript enabled
        in order for this application to display correctly.
      </div>
    </noscript>

    <h1>掲示板(Java版）</h1>
    <form action="/bullentinboard/greet" name = "input" method="post" onSubmit = "return chkInput(this)">
    <table>
      <tr>
        <td style="font-weight:bold;">投稿者</td>
<!-- upd start by Karibe -->
<!--        <th > <textarea name="name" rows = "1" cols = "50"></textarea> </th>  -->
        <td><input type="text" name="name" size="30" maxlength="15"></input></td>
<!-- upd end   by Karibe -->
      </tr>
      <tr>
        <td style="font-weight:bold;">E-mail</td>
<!-- upd start by Karibe -->
<!--        <th> <textarea name="email" rows = "1" cols = "50" ></textarea> </th> -->       
        <td><input type="text" name="email" size="45" maxlength="40"></input></td>
<!-- upd end   by Karibe -->
      </tr>
      <tr>
        <td style="font-weight:bold;">題名</td>
<!-- upd start by Karibe -->
<!--        <th> <textarea name="title" rows = "1" cols = "50"></textarea> </th> -->     
        <td><input type="text" name="title" size="45" maxlength="25"></input></td>
<!-- upd end   by Karibe -->
      </tr>
<!-- upd start by Karibe -->
<!--      <tr> -->
<!--        <td style="font-weight:bold;">内容</td> -->
<!--        <th> <textarea name="content" rows = "5" cols = "50"></textarea> </th> -->       
<!--      </tr> -->
<!--      <tr> -->
<!--        <td> </td> -->  
<!--        <th align = "right"><input type=submit value="メッセージ送信" ><input type=reset value="キャンセル" ></th> -->
<!--      </tr> -->
    </table>
    <div><textarea name="content" rows="6" cols="60"></textarea></div>
    <input type="submit" value="書き込み"></input>
    <input type="reset" value="取り消し"></input>
    </form>
<!-- upd end   by Karibe -->
    <br>
  <%
  PersistenceManager pm = PMF.get().getPersistenceManager();
  String query = "select from " + Greeting.class.getName() + " order by date desc";
  List<Greeting> greetings = (List<Greeting>) pm.newQuery(query).execute();
        
  for (Greeting g:greetings) {
    String chkemail = g.getEmail(); 
    if ((g.getEmail() == null)
        ||"".equals(g.getEmail())) {
  %>
        <p><b><%=g.getName() %></b>さんの書き込み(<%=g.getDate() %>)：<b><%=g.getTitle()%></b></p>
  <%
    } else {
  %>
        <p><b><a href = "mailto:<%=g.getEmail() %>"><%=g.getName() %></b></a>さんの書き込み(<%=g.getDate() %>)：<b><%=g.getTitle()%></b></p>
 <%
    }
 %>
<!-- upd start by Karibe -->
<!--    <blockquote><%=g.getContent() %></blockquote> -->
    <blockquote><%=g.getContent().replace("\n","<br>")%></blockquote>
<!-- upd end   by Karibe -->
  <%
  }
  
  pm.close();
  %>
  </body>
</html>
